<?php
/**
 * Created by PhpStorm.
 * User: wodrow
 * Date: 8/14/17
 * Time: 3:06 PM
 */

namespace console\modules\unionpay\controllers;


use common\components\tools\Api;
use common\components\tools\Tools;
use common\models\credit_public\SlCheck1004;
use common\models\credit_public\SlCheck1009;
use common\models\credit_public\SlCheck1025;
use yii\console\Controller;

class BatchController extends Controller
{
    public function actionRun1004()
    {
        /**
         * @var SlCheck1004[] $has_no_checks
         */
        $has_no_checks = SlCheck1004::find()->where(['c_issame'=>null])->all();
        foreach ($has_no_checks as $k => $v){
            $r = Api::request('/unionpay/business/card-no4', [
                'usrName' => $v->c_name,
                'cardNo' => $v->c_bankcard,
                'certNo' => $v->c_card,
            ]);
            var_export($r);
            sleep(5);
        }
        /*$has_no_checks = SlCheck1004::find()->where(['or', ['<>', 'c_issame', "认证/查询成功"], ['c_issame'=>null]])->all();
        foreach ($has_no_checks as $k => $v){
            $b1 = $v->c_source==SlCheck1004::SOURCE_UNIONPAY;
            $b2 = time()-$v->c_time<86400*30;
//            $b3 = $b1&&$b2;
            $b4 = in_array($v->c_issame, ['商户报文字段[cardPhone]段缺失', '商户报文字段[cardNo]段缺失']);
            $b = !$b1||!$b2||$b4; // 需要重新请求查询条件
            if (!$b){}else{
                $r = Api::request('unionpay/business/card-no4', [
                    'usrName' => $v->c_name,
                    'cardNo' => $v->c_bankcard,
                    'certNo' => $v->c_card,
                ]);
//                $x = Tools::objectToArray(json_decode($r->content));
//                var_export($x['data']['sl_check']['c_issame']);
            }
        }*/
    }

    public function actionRun1025()
    {
        /**
         * @var SlCheck1025[] $has_no_checks
         */
        $has_no_checks = SlCheck1025::find()->where(['perfer_back'=>null])->all();
        foreach ($has_no_checks as $k => $v){
            $r = Api::request('/unionpay/business/operator3', [
                'usrName' => $v->c_name,
                'mobile' => $v->c_tel,
                'certNo' => $v->c_card,
            ]);
            var_export($r);
            sleep(5);
        }
        /*$has_no_checks = SlCheck1025::find()->where(['or', ['<>', 'perfer_back', "认证/查询成功"], ['perfer_back'=>null]])->all();
        foreach ($has_no_checks as $k => $v){
            $b1 = $v->c_source==SlCheck1004::SOURCE_UNIONPAY;
            $b2 = time()-$v->c_time<86400*30;
//            $b3 = $b1&&$b2;
            $b4 = in_array($v->perfer_back, ['商户报文字段[cardPhone]段缺失', '商户报文字段[cardNo]段缺失']);
            $b = !$b1||!$b2||$b4; // 需要重新请求查询条件
            if (!$b){}else{
                $r = Api::request('unionpay/business/operator3', [
                    'usrName' => $v->c_name,
                    'mobile' => $v->c_tel,
                    'certNo' => $v->c_card,
                ]);
                var_export($r);
            }
        }*/
    }

    public function actionRun1009()
    {
        /**
         * @var SlCheck1009[] $has_no_checks
         */
        $has_no_checks = SlCheck1009::find()->where(['perfer_back'=>null])->all();
        foreach ($has_no_checks as $k => $v){
            $r = Api::request('/unionpay/business/personal-id-evn', [
                'certNo' => $v->c_card,
            ]);
            var_export($r);
            sleep(5);
        }
    }
}